// pages/approve/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderIndex: 0,
    orderList: ['显示全部', 'xxxxx'],

    tab: 0,

    refreashLoading: false,
    loading: false,
    lineList: [],
    pageIdx: 1,
    pageSize: 30
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getMoreList()
  },

  switchNav(e) {
    const {
      currentTarget
    } = e;
    if(this.data.loading) return
    this.setData({
      tab: Number(currentTarget.dataset.index)
    })

    this.getMoreList();
  },
  // 修改当前选择
  bindChangeOrder(e) {
    console.log('e=====>', e);
    const {
      detail
    } = e;
    this.setData({
      orderIndex: Number(detail.value)
    })
  },
  getMoreList(page = 1) {
    console.log('page===>', page);
    this.setData({
      loading: true,
      pageIdx: page,
    })

    const _lineList = this.data.lineList;
    const newLineList = [...new Array(30 * this.data.pageIdx)].map((_, i) => {
      return {
        order: i + 1,
        type: i + 1,
        write: i + 1,
      }
    })
    setTimeout(() => {
      this.setData({
        loading: false,
        refreashLoading: false,
        lineList: [
          ..._lineList,
          ...newLineList
        ],
      })
    }, 2 * 1000)
  },
  // 刷新
  refreashMoreLine() {
    if (this.data.loading) return;
    this.setData({
      refreashLoading: true
    })
    this.getMoreList()
  },
  // 下一页
  getNextMoreLine() {
    if (this.data.loading) return;
    this.setData({
      pageIdx: this.data.pageIdx + 1
    })

    this.getMoreList(this.data.pageIdx)
  },
  // 去详情页
  goDetail(e) {
    const {
      currentTarget
    } = e;
    wx.navigateTo({
      url: `/pages/approve/detail/index?id=${currentTarget.dataset.order}`
    })
  },
})